//
// Ephi - simulation of magnetic fields and particles
// Copyright (C) 2007 Indrek Mandre <indrek(at)mare.ee>
// For more information please see http://www.mare.ee/indrek/
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along
// with this program; if not, write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
//

// Precalculate coil data and store it into a file

#include "ephi.hpp"

static void usage (const char *name)
{
  fprintf (stderr, "%s: %s\n", name, name);
  exit(-1);
}

int main(int argc, char *argv[])
{
  CoilGen cgen;

  const char *path = "out.cgen";

  for ( int i = 1; i < argc; i++ )
    {
      if ( argv[i][0] != '-' )
          usage(argv[0]);
      switch ( argv[i][1] )
        {
          case '3': {
            cgen.do_cubic = true;
            break;
          }
          case 'd': {
            if ( ++i == argc )
                usage(argv[0]);
            cgen.dbl = atof(argv[i]);
            break;
          }
          case 's': {
            if ( ++i == argc )
                usage(argv[0]);
            cgen.set_space (atof(argv[i]));
            break;
          }
          case 'c': {
            if ( ++i == argc )
                usage(argv[0]);
            if ( !strcmp(argv[i], "square") )
                cgen.shape = CoilGen::SQUARE;
            else if ( !strcmp (argv[i], "round") )
                cgen.shape = CoilGen::ROUND;
            else
                usage(argv[0]);
            break;
          }
          case 'r': {
            if ( ++i == argc )
                usage(argv[0]);
            cgen.radius = atof(argv[i]);
            break;
          }
          case 'w': {
            if ( ++i == argc )
                usage(argv[0]);
            cgen.wr = atof(argv[i]);
            break;
          }
          case 'm': {
            if ( ++i == argc )
                usage(argv[0]);
            cgen.memory_usage = atoi(argv[i]);
            break;
          }
          case 'n': {
            if ( ++i == argc )
                usage(argv[0]);
            cgen.coil_matrix_n = atoi(argv[i]);
            break;
          }
          case 'o': {
            if ( ++i == argc )
                usage(argv[0]);
            path = argv[i];
            break;
          }
          case 'e': {
            cgen.do_efield = true;
            break;
          }
          case 'g': {
            if ( ++i == argc )
                usage(argv[0]);
            double gr, ga;
            sscanf (argv[i], "%lfx%lf", &gr, &ga);
            cgen.geom_radial = gr;
            cgen.geom_axial = ga;
            break;
          }
          case 'f': {
            if ( ++i == argc )
                usage(argv[0]);
            cgen.force_grid = atoi(argv[i]);
            break;
          }
          default: {
            usage(argv[0]);
            break;
          }
        }
    }

  cgen.generate (path, true, true);

  return 0;
}

